<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:form="http://java.sun.com/jsf/composite/components/form"
	xmlns:sec="http://www.springframework.org/security/tags"
	template="/templates/include/securedmain.xhtml">

	<ui:define name="content">
		<h:form id="form">
			<p:growl id="growl" showDetail="true" sticky="false" />
			<p:dataTable var="obj" value="#{objectsTableBean.objectDataModel}"
				paginator="true" rows="10"
				filteredValue="#{objectsTableBean.filteredObjects}"
				selection="#{objectsTableBean.selectedObjects}" id="objectsTable">

				<!-- This is a workaround for proper multiselection (guys from prime are loosers) -->
				<p:ajax event="toggleSelect" update="@this" process="@this" />
				<p:ajax event="rowSelectCheckbox" update="@this" />
				<p:ajax event="rowUnselectCheckbox" update="@this" />
				<p:ajax event="rowSelect" update="@this" />
				<p:ajax event="rowUnselect" update="@this" />
				<p:column selectionMode="multiple" style="width:2%" />

				<f:facet name="header">
					#{msg['menu.main.objectmanagement']}
				</f:facet>

				<p:column headerText="#{msg['properties.object.name']}" id="name"
					filterBy="#{obj.name}">
					<h:outputText value="#{obj.name}" />
				</p:column>

				<p:column headerText="#{msg['properties.object.identifier']}"
					id="identifier" filterBy="#{obj.identifier}">
					<!-- 					 filterBy="#{obj.identifier}"> -->
					<h:outputText value="#{obj.identifier}" />
				</p:column>

				<p:column headerText="#{msg['properties.objectclass.name']}"
					id="objcl" filterBy="#{obj.objectClass.name}">

					<h:outputText value="#{obj.objectClass.name}" />
				</p:column>

				<p:column headerText="#{msg['view.actions']}" id="editAcs">
					<sec:authorize ifAnyGranted="ROLE_ADMIN, ROLE_MASTER">
						<p:button id="qrButton" outcome="generateqr"
							onclick="window.open('generateqr.jsf?id=#{obj.id}'); return false;"
							title="#{msg['view.actions.qrcode']}" icon="ui-icon-print"
							update="@form" ajax="false">
							<f:param name="id" value="#{obj.id}" />
						</p:button>

						<p:button id="editButton" outcome="/admin/edit/editobject"
							title="#{msg['view.actions.edit']}" icon="ui-icon-pencil"
							update="@form" ajax="false">
							<f:param name="id" value="#{obj.id}" />
						</p:button>
					</sec:authorize>

					<p:button id="viewButton" outcome="view/viewobject"
						title="#{msg['view.actions.view']}" icon="ui-icon-search"
						update="@form" ajax="false">
						<f:param name="id" value="#{obj.id}" />
					</p:button>

					<sec:authorize ifAnyGranted="ROLE_ADMIN, ROLE_MASTER">

						<p:button id="calendarButton" outcome="objectcalendar"
							title="#{msg['view.actions.calendar']}" icon="ui-icon-calendar"
							update="@form" ajax="false">
							<f:param name="id" value="#{obj.id}" />
						</p:button>
					</sec:authorize>
					<sec:authorize ifAnyGranted="ROLE_USER">
						<p:button id="calendarButton" outcome="objectusercalendar"
							title="#{msg['view.actions.calendar']}" icon="ui-icon-calendar"
							update="@form" ajax="false">
							<f:param name="id" value="#{obj.id}" />
						</p:button>
					</sec:authorize>
				</p:column>

				<f:facet name="footer">
					<sec:authorize ifAnyGranted="ROLE_ADMIN">
						<p:commandButton id="showDialogButton"
							value="#{msg['view.actions.delete']}" icon="ui-icon-trash"
							onclick="confirmation.show()" type="button" />
						<p:button id="createObjectButton"
							value="#{msg['view.actions.create']}" icon="ui-icon-circle-plus"
							outcome="/admin/edit/createobject" />
					</sec:authorize>
				</f:facet>
			</p:dataTable>
		</h:form>
		<p:confirmDialog id="confirmDialog" appendToBody="true"
			message="#{msg['view.actions.delete.label']}"
			header="#{msg['view.actions.delete']}" severity="alert"
			widgetVar="confirmation">
				<!-- update="messages" -->
				<p:commandButton id="confirm"
					value="#{msg['view.actions.button.commit']}"
					oncomplete="confirmation.hide()"
					actionListener="#{objectsTableBean.deleteSelectedObjects}"
					update="form" />
				<p:commandButton id="decline"
					value="#{msg['view.actions.button.cancel']}"
					onclick="confirmation.hide()" type="button" />
		</p:confirmDialog>

	</ui:define>
</ui:composition>
